<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="中文标题" prop="chineseTitle">
        <el-input
          v-model="queryParams.chineseTitle"
          placeholder="请输入中文标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="中文标题-图谱" prop="chineseTitleKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.chineseTitleKg"-->
<!--          placeholder="请输入中文标题-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="英文标题" prop="englishTitle">
        <el-input
          v-model="queryParams.englishTitle"
          placeholder="请输入英文标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="英文标题-图谱" prop="englishTitleKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.englishTitleKg"-->
<!--          placeholder="请输入英文标题-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="国别" prop="category">
        <el-input
          v-model="queryParams.category"
          placeholder="请输入国别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="所属领域" prop="field">-->
<!--        <el-input-->
<!--          v-model="queryParams.field"-->
<!--          placeholder="请输入所属领域"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="发布机构" prop="publishingAgency">-->
<!--        <el-input-->
<!--          v-model="queryParams.publishingAgency"-->
<!--          placeholder="请输入发布机构"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="发布机构-图谱" prop="publishingAgencyKg">-->
<!--        <el-input-->
<!--          v-model="queryParams.publishingAgencyKg"-->
<!--          placeholder="请输入发布机构-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="发布时间" prop="releaseDate">-->
<!--        <el-input-->
<!--          v-model="queryParams.releaseDate"-->
<!--          placeholder="请输入发布时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="发布时间-图谱" prop="releaseDateMap">-->
<!--        <el-input-->
<!--          v-model="queryParams.releaseDateMap"-->
<!--          placeholder="请输入发布时间-图谱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="文件页数" prop="pageCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.pageCount"-->
<!--          placeholder="请输入文件页数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="字数" prop="wordCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.wordCount"-->
<!--          placeholder="请输入字数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="定位" prop="position">-->
<!--        <el-input-->
<!--          v-model="queryParams.position"-->
<!--          placeholder="请输入定位"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="类别属性" prop="categoryAttribute">
        <el-input
          v-model="queryParams.categoryAttribute"
          placeholder="请输入类别属性"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="关键词" prop="keyword">-->
<!--        <el-input-->
<!--          v-model="queryParams.keyword"-->
<!--          placeholder="请输入关键词"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:policie:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:policie:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:policie:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="policieList" @selection-change="handleSelectionChange">
      <el-table-column type="selection"  show-overflow-tooltip    width="55" align="center" />
      <el-table-column label="主键ID，自动递增" show-overflow-tooltip     align="center" prop="id" />
      <el-table-column label="中文标题"  show-overflow-tooltip    align="center" prop="chineseTitle" />
      <el-table-column label="中文标题-图谱" show-overflow-tooltip     align="center" prop="chineseTitleKg" />
      <el-table-column label="英文标题"  show-overflow-tooltip    align="center" prop="englishTitle" />
      <el-table-column label="英文标题-图谱" align="center" prop="englishTitleKg" />
      <el-table-column label="国别"  show-overflow-tooltip    align="center" prop="category" />
      <el-table-column label="所属领域" show-overflow-tooltip     align="center" prop="field" />
      <el-table-column label="发布机构" show-overflow-tooltip     align="center" prop="publishingAgency" />
      <el-table-column label="发布机构-图谱" show-overflow-tooltip     align="center" prop="publishingAgencyKg" />
      <el-table-column label="发布时间"  show-overflow-tooltip    align="center" prop="releaseDate" />
      <el-table-column label="发布时间-图谱"  show-overflow-tooltip    align="center" prop="releaseDateMap" />
      <el-table-column label="文件页数" show-overflow-tooltip     align="center" prop="pageCount" />
      <el-table-column label="字数" show-overflow-tooltip     align="center" prop="wordCount" />
      <el-table-column label="定位" show-overflow-tooltip     align="center" prop="position" />
      <el-table-column label="是否涉我 (1:是, 0:否)" show-overflow-tooltip     align="center" prop="isRelevant" />
      <el-table-column label="类别属性" show-overflow-tooltip     align="center" prop="categoryAttribute" />
      <el-table-column label="类别属性-图谱"  show-overflow-tooltip    align="center" prop="categoryAttributeKg" />
      <el-table-column label="摘要" show-overflow-tooltip     align="center" prop="summary" />
      <el-table-column label="文件目录内容" show-overflow-tooltip     align="center" prop="contentDirectory" />
      <el-table-column label="关键词"  show-overflow-tooltip    align="center" prop="keyword" />
<!--      <el-table-column label="关联文件" show-overflow-tooltip     align="center" prop="relatedFile" />-->
<!--      <el-table-column label="关联文件-图谱" show-overflow-tooltip     align="center" prop="relatedFileKg" />-->
<!--      <el-table-column label="${comment}" show-overflow-tooltip     align="center" prop="allInfo" />-->
      <el-table-column label="新字段2025" show-overflow-tooltip     align="center" prop="xinZiDuan2025" />
      <el-table-column label="操作"  fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:policie:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:policie:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改战略政策对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="中文标题" prop="chineseTitle">
          <el-input v-model="form.chineseTitle" placeholder="请输入中文标题" />
        </el-form-item>
        <el-form-item label="中文标题-图谱" prop="chineseTitleKg">
          <el-input v-model="form.chineseTitleKg" placeholder="请输入中文标题-图谱" />
        </el-form-item>
        <el-form-item label="英文标题" prop="englishTitle">
          <el-input v-model="form.englishTitle" placeholder="请输入英文标题" />
        </el-form-item>
        <el-form-item label="英文标题-图谱" prop="englishTitleKg">
          <el-input v-model="form.englishTitleKg" placeholder="请输入英文标题-图谱" />
        </el-form-item>
        <el-form-item label="国别" prop="category">
          <el-input v-model="form.category" placeholder="请输入国别" />
        </el-form-item>
        <el-form-item label="所属领域" prop="field">
          <el-input v-model="form.field" placeholder="请输入所属领域" />
        </el-form-item>
        <el-form-item label="发布机构" prop="publishingAgency">
          <el-input v-model="form.publishingAgency" placeholder="请输入发布机构" />
        </el-form-item>
        <el-form-item label="发布机构-图谱" prop="publishingAgencyKg">
          <el-input v-model="form.publishingAgencyKg" placeholder="请输入发布机构-图谱" />
        </el-form-item>
        <el-form-item label="发布时间" prop="releaseDate">
          <el-input v-model="form.releaseDate" placeholder="请输入发布时间" />
        </el-form-item>
        <el-form-item label="发布时间-图谱" prop="releaseDateMap">
          <el-input v-model="form.releaseDateMap" placeholder="请输入发布时间-图谱" />
        </el-form-item>
        <el-form-item label="文件页数" prop="pageCount">
          <el-input v-model="form.pageCount" placeholder="请输入文件页数" />
        </el-form-item>
        <el-form-item label="字数" prop="wordCount">
          <el-input v-model="form.wordCount" placeholder="请输入字数" />
        </el-form-item>
        <el-form-item label="定位" prop="position">
          <el-input v-model="form.position" placeholder="请输入定位" />
        </el-form-item>
        <el-form-item label="是否涉我 (1:是, 0:否)" prop="isRelevant">
          <el-input v-model="form.isRelevant" placeholder="请输入是否涉我 (1:是, 0:否)" />
        </el-form-item>
        <el-form-item label="类别属性" prop="categoryAttribute">
          <el-input v-model="form.categoryAttribute" placeholder="请输入类别属性" />
        </el-form-item>
        <el-form-item label="类别属性-图谱" prop="categoryAttributeKg">
          <el-input v-model="form.categoryAttributeKg" placeholder="请输入类别属性-图谱" />
        </el-form-item>
        <el-form-item label="摘要" prop="summary">
          <el-input v-model="form.summary" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="文件目录内容" prop="contentDirectory">
          <el-input v-model="form.contentDirectory" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="关键词" prop="keyword">
          <el-input v-model="form.keyword" placeholder="请输入关键词" />
        </el-form-item>
<!--        <el-form-item label="关联文件" prop="relatedFile">-->
<!--          <file-upload v-model="form.relatedFile"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="关联文件-图谱" prop="relatedFileKg">-->
<!--          <el-input v-model="form.relatedFileKg" placeholder="请输入关联文件-图谱" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="${comment}" prop="allInfo">-->
<!--          <el-input v-model="form.allInfo" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
        <el-form-item label="新字段2025" prop="xinZiDuan2025">
          <el-input v-model="form.xinZiDuan2025" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="图片" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'image'"
              :biz-type="'download'"
              :limit="1"
              style="margin-left: 20px"
              table-type="6"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="原文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz001'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="6"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="译文文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz002'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="6"
            ></FileUpload>
          </div>
        </el-form-item>

      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="精翻文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz003'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="6"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPolicie, getPolicie, delPolicie, addPolicie, updatePolicie } from "@/api/business/policie";
import { guid } from '@/utils/utils'
import FileUpload from '@/components/fileUpload_neww.vue'
import Pictures from '@/components/Pictures'
export default {
  name: "Policie",
  components: { Pictures,FileUpload },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 战略政策表格数据
      policieList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        chineseTitle: null,
        chineseTitleKg: null,
        englishTitle: null,
        englishTitleKg: null,
        category: null,
        field: null,
        publishingAgency: null,
        publishingAgencyKg: null,
        releaseDate: null,
        releaseDateMap: null,
        pageCount: null,
        wordCount: null,
        position: null,
        isRelevant: null,
        categoryAttribute: null,
        categoryAttributeKg: null,
        summary: null,
        contentDirectory: null,
        keyword: null,
        relatedFile: null,
        relatedFileKg: null,
        allInfo: null,
        xinZiDuan2025: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        chineseTitle: [
          { required: true, message: "中文标题不能为空", trigger: "blur" }
        ],
        chineseTitleKg: [
          { required: true, message: "中文标题-图谱不能为空", trigger: "blur" }
        ],
        englishTitle: [
          { required: true, message: "英文标题不能为空", trigger: "blur" }
        ],
        englishTitleKg: [
          { required: true, message: "英文标题-图谱不能为空", trigger: "blur" }
        ],
        category: [
          { required: true, message: "国别不能为空", trigger: "blur" }
        ],
        field: [
          { required: true, message: "所属领域不能为空", trigger: "blur" }
        ],
        publishingAgency: [
          { required: true, message: "发布机构不能为空", trigger: "blur" }
        ],
        publishingAgencyKg: [
          { required: true, message: "发布机构-图谱不能为空", trigger: "blur" }
        ],
        releaseDate: [
          { required: true, message: "发布时间不能为空", trigger: "blur" }
        ],
        releaseDateMap: [
          { required: true, message: "发布时间-图谱不能为空", trigger: "blur" }
        ],
        pageCount: [
          { required: true, message: "文件页数不能为空", trigger: "blur" }
        ],
        wordCount: [
          { required: true, message: "字数不能为空", trigger: "blur" }
        ],
        position: [
          { required: true, message: "定位不能为空", trigger: "blur" }
        ],
        isRelevant: [
          { required: true, message: "是否涉我 (1:是, 0:否)不能为空", trigger: "blur" }
        ],
        categoryAttribute: [
          { required: true, message: "类别属性不能为空", trigger: "blur" }
        ],
        categoryAttributeKg: [
          { required: true, message: "类别属性-图谱不能为空", trigger: "blur" }
        ],
        summary: [
          { required: true, message: "摘要不能为空", trigger: "blur" }
        ],
        keyword: [
          { required: true, message: "关键词不能为空", trigger: "blur" }
        ],
        relatedFile: [
          { required: true, message: "关联文件不能为空", trigger: "blur" }
        ],
        relatedFileKg: [
          { required: true, message: "关联文件-图谱不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询战略政策列表 */
    getList() {
      this.loading = true;
      listPolicie(this.queryParams).then(response => {
        this.policieList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        chineseTitle: null,
        chineseTitleKg: null,
        englishTitle: null,
        englishTitleKg: null,
        category: null,
        field: null,
        publishingAgency: null,
        publishingAgencyKg: null,
        releaseDate: null,
        releaseDateMap: null,
        pageCount: null,
        wordCount: null,
        position: null,
        isRelevant: null,
        categoryAttribute: null,
        categoryAttributeKg: null,
        summary: null,
        contentDirectory: null,
        keyword: null,
        relatedFile: null,
        relatedFileKg: null,
        allInfo: null,
        xinZiDuan2025: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加战略政策";
      let mizId = guid().replace(/-/g, '');
      this.form.id = mizId
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPolicie(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改战略政策";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePolicie(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPolicie(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除战略政策编号为"' + ids + '"的数据项？').then(function() {
        return delPolicie(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/policie/export', {
        ...this.queryParams
      }, `policie_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
